<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>{$vote.name}</title>
</head>
<!-- 这里使用了一张背景，注释掉了。
<body style="background-image:url(body.jpeg); background-size:100%; background-repeat: no-repeat;">
 -->
 <body>
	<div  align="center">
	<h4>{$vote.name}投票</h4>
	<form action="" method="post" id="form">
		<table id="main" >
			
			<foreach name="item" item="vo" key="key">
			<tr >
				<td>
					<label><input class="vote" value="{$vo.id}" type="<if condition="$vote['everytime'] gt 1">checkbox<else />radio</if>" name="id[]" />{$vo.name} <if condition="!empty($vo['image'])"><img style="max-width: 144px;" src="{:cmf_get_image_url($vo['image'])}"></if></label>
				</td>
			</tr>
			<tr>
				<td style="width:550px">
					<div class="jd" id="{$vo.id}" style="background-color:#acd6ff; width:<if condition="$maxcount eq 0">0<else />{:ceil(540/$maxcount*$vo['count'])}</if>px; height:20px; border-width:0px;">
					</div>
				</td>
				<td>
					<label id="label{$vo.id}">{$vo['count']}</label>票
				</td>
			</tr>
			</foreach>
		
			<tr>
				<td><p>
					<input type="button" value="确认投票" onclick="vote()"/>		
				</td>
			</tr>
		</table>
		</form>
	</div>
</body>
    <script src="__ADMIN_TMPL__/public/assets/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
	d = <if condition="$maxcount eq 0">0<else />{:ceil(540/$maxcount)}</if>;
	everytime = {$vote['everytime']}
	//在每个投票选项后面写了个div，用div的宽度来代表当前该选项的投票数。
	function vote(){
		//函数vote，当点击确认投票的时候，调用vote方法
		
		checkedcount = 0;
		$('input').each(function(){
			if($(this).is(":checked")){
				checkedcount++;
			}
		});
		
		if(checkedcount>everytime){
			alert('最多选择'+everytime+'项')
			return
		}
		
		data = $('#form').serializeArray();
		$.post('{:cmf_plugin_url('QbtVote://AdminIndex/vote',['id'=>$vote['id']])}',data,function(res){
			if(res.code == 1){
				alert(res.msg)
				window.location = '{:cmf_plugin_url('QbtVote://AdminIndex/vote',['id'=>$vote['id']])}'
				/*
				$('input').each(function(){
					if($(this).is(":checked")){
						width = $('#'+$(this).val()).width();
						$('#'+$(this).val()).css('width',width+d);
						$('#label'+$(this).val()).text(parseInt($('#label'+$(this).val()).text())+1);
					}
				});*/
			}else{
				alert(res.msg)
			}
			
			
		});
		
		
		
		
	}

</script>
</html>